/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * <p>Project: jse2302 - File1
 * <p>Powered by webrx On 2023-06-26 17:00:19
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class File1 {
    public static void main(String[] args) throws Exception {
        //建立内容，并将内容写入文件中
        //String path = "c:/abc";
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        //Random rand = new Random();
        //for (int i = 0; i < 10; i++) {
        //    String filename = String.format("%s_%06d.html", sdf.format(new Date()),rand.nextInt(999999));
        //    FileWriter out = new FileWriter(path + "/" + filename);
        //    out.write("hello java中文\r\n");
        //    out.write(UUID.randomUUID().toString().toLowerCase());
        //    out.close();
        //}

        //建立文件
        String file = "user.txt";
        //true代码追加模式，建立文件，如果文件不存在就建立，如果存在，就在尾部追加信息
        var out = new FileWriter(file,true);
        out.write("hello 用户\r\n");
        out.write(UUID.randomUUID().toString().toLowerCase()+"\r\n");
        out.write(UUID.randomUUID().toString().toUpperCase()+"\r\n");
        out.close();

        //删除文件
        //File f = new File(file);
        //if(f.exists()){
        //    f.deleteOnExit();
        //}

        //读取文件
        FileInputStream fis = new FileInputStream(file);
        String txt = new String(fis.readAllBytes());
        System.out.println(txt.lines().count());
        System.out.println("-------------------------------");
        System.out.println(txt);
    }
}
